package com.ruoyi.system.mapper;

import java.util.List;
import com.ruoyi.system.domain.FyData;
import com.ruoyi.system.domain.vo.AdminHomeCountVo;
import com.ruoyi.system.domain.vo.AdminHomehexinCountVo;
import com.ruoyi.system.domain.vo.HomeCountVo;
import com.ruoyi.system.domain.vo.web.WebFyDataVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 资料Mapper接口
 *
 * @author ruoyi
 * @date 2025-06-05
 */
public interface FyDataMapper
{
    /**
     * 查询资料
     *
     * @param dataId 资料主键
     * @return 资料
     */
    public FyData selectFyDataByDataId(Long dataId);

    @Select("SELECT  \n" +
            " (SELECT COUNT(*) FROM fy_project where is_delete = 0) AS project,\n" +
            " ((select count(1) from fy_project a ,fy_data b where a.project_id=b.project_id)+\n" +
            "(select count(1) from fy_people a ,fy_data b where a.people_id=b.people_id)\n" +
            ") + (SELECT COUNT(*) FROM fy_resources where is_delete = 0)+(SELECT dict_sort FROM sys_dict_data WHERE dict_code = 122 ) +(SELECT dict_sort FROM sys_dict_data WHERE dict_code = 124 )AS data,\n" +
            " (SELECT COUNT(*) FROM  fy_people where is_delete = 0) AS people,\n" +
            " (SELECT COUNT(*) FROM  fy_resources where is_delete = 0)+(SELECT dict_sort FROM sys_dict_data WHERE dict_code = 123 ) AS resources;")
    public HomeCountVo selectHomecount();
    @Select("SELECT  \n" +
            "((select count(1) from fy_project a ,fy_data b where a.project_id=b.project_id)+\n" +
            "(select count(1) from fy_people a ,fy_data b where a.people_id=b.people_id)\n" +
            ")+ (SELECT COUNT(*) FROM fy_resources where is_delete=0)+(SELECT dict_sort FROM sys_dict_data WHERE dict_code = 122 )+(SELECT dict_sort FROM sys_dict_data WHERE dict_code = 124 ) AS ziyuanzongliang,\n" +
            "((select count(1) from fy_project a ,fy_data b where a.project_id=b.project_id)+\n" +
            "(select count(1) from fy_people a ,fy_data b where a.people_id=b.people_id)+(SELECT dict_sort FROM sys_dict_data WHERE dict_code = 124 )\n" +
            ") as hexinziyyuanzongliang, \n" +
            "(SELECT COUNT(*) FROM fy_resources WHERE is_delete = 0 )+(SELECT dict_sort FROM sys_dict_data WHERE dict_code = 123 ) as kuozhanziyuan, \n" +
            "(SELECT COUNT(*) FROM fy_project WHERE is_delete = 0) as xiangmushu, (SELECT COUNT(*) FROM fy_people WHERE is_delete = 0) as chuanchengren;")
    public AdminHomeCountVo selectAdminHomecountShujuzonglan();
    @Select("\n" +
            " SELECT \n" +
            "    SUM(ziyuanzongliang) AS zongziyuan,  \n" +
            "    SUM(guojiaji) AS guojiaji,          \n" +
            "    SUM(quji) AS quji,                  \n" +
            "    SUM(shiji) AS shiji,                \n" +
            "    SUM(chuantongyiyao) AS chuantongyiyao,\n" +
            "    SUM(chuantongjiyi) AS chuantongjiyi,\n" +
            "    SUM(tiyuzaji) AS tiyuzaji,\n" +
            "    SUM(minsu) AS minsu,\n" +
            "    SUM(chuantongwudao) AS chuantongwudao,\n" +
            "    SUM(chuantongmeishu) AS chuantongmeishu,\n" +
            "    SUM(chuantongyinyue) AS chuantongyinyue,\n" +
            "    SUM(chuantongxiju) AS chuantongxiju,\n" +
            "    SUM(quyi) AS quyi,\n" +
            "    SUM(minjinwenxue) AS minjinwenxue\n" +
            "FROM (\n" +
            "    SELECT \n" +
            "        COUNT(*) AS ziyuanzongliang, \n" +
            "        SUM(CASE WHEN project_level = '国家级' THEN 1 ELSE 0 END) AS guojiaji, \n" +
            "        SUM(CASE WHEN project_level = '区级' THEN 1 ELSE 0 END) AS quji, \n" +
            "        SUM(CASE WHEN project_level = '市级' THEN 1 ELSE 0 END) AS shiji, \n" +
            "        SUM(CASE WHEN project_type = '传统医药' THEN 1 ELSE 0 END) AS chuantongyiyao, \n" +
            "        SUM(CASE WHEN project_type = '传统技艺' THEN 1 ELSE 0 END) AS chuantongjiyi, \n" +
            "        SUM(CASE WHEN project_type = '传统体育、游艺与杂技' THEN 1 ELSE 0 END) AS tiyuzaji, \n" +
            "        SUM(CASE WHEN project_type = '民俗' THEN 1 ELSE 0 END) AS minsu, \n" +
            "        SUM(CASE WHEN project_type = '传统舞蹈' THEN 1 ELSE 0 END) AS chuantongwudao, \n" +
            "        SUM(CASE WHEN project_type = '传统美术' THEN 1 ELSE 0 END) AS chuantongmeishu, \n" +
            "        SUM(CASE WHEN project_type = '传统音乐' THEN 1 ELSE 0 END) AS chuantongyinyue, \n" +
            "        SUM(CASE WHEN project_type = '传统戏剧' THEN 1 ELSE 0 END) AS chuantongxiju, \n" +
            "        SUM(CASE WHEN project_type = '曲艺' THEN 1 ELSE 0 END) AS quyi, \n" +
            "        SUM(CASE WHEN project_type = '民间文学' THEN 1 ELSE 0 END) AS minjinwenxue \n" +
            "    FROM fy_project a \n" +
            "    JOIN fy_data b ON a.project_id = b.project_id \n" +
            "    UNION ALL\n" +
            "    SELECT \n" +
            "        COUNT(*) AS ziyuanzongliang, \n" +
            "        SUM(CASE WHEN people_level = '国家级' THEN 1 ELSE 0 END) AS guojiaji, \n" +
            "        SUM(CASE WHEN people_level = '区级' THEN 1 ELSE 0 END) AS quji, \n" +
            "        SUM(CASE WHEN people_level = '市级' THEN 1 ELSE 0 END) AS shiji, \n" +
            "        SUM(CASE WHEN project_type = '传统医药' THEN 1 ELSE 0 END) AS chuantongyiyao, \n" +
            "        SUM(CASE WHEN project_type = '传统技艺' THEN 1 ELSE 0 END) AS chuantongjiyi, \n" +
            "        SUM(CASE WHEN project_type = '传统体育、游艺与杂技' THEN 1 ELSE 0 END) AS tiyuzaji, \n" +
            "        SUM(CASE WHEN project_type = '民俗' THEN 1 ELSE 0 END) AS minsu, \n" +
            "        SUM(CASE WHEN project_type = '传统舞蹈' THEN 1 ELSE 0 END) AS chuantongwudao, \n" +
            "        SUM(CASE WHEN project_type = '传统美术' THEN 1 ELSE 0 END) AS chuantongmeishu, \n" +
            "        SUM(CASE WHEN project_type = '传统音乐' THEN 1 ELSE 0 END) AS chuantongyinyue, \n" +
            "        SUM(CASE WHEN project_type = '传统戏剧' THEN 1 ELSE 0 END) AS chuantongxiju, \n" +
            "        SUM(CASE WHEN project_type = '曲艺' THEN 1 ELSE 0 END) AS quyi, \n" +
            "        SUM(CASE WHEN project_type = '民间文学' THEN 1 ELSE 0 END) AS minjinwenxue \n" +
            "    FROM fy_people a \n" +
            "    JOIN fy_data b ON a.people_id = b.people_id \n" +
            ") AS combined_results;")
    public AdminHomehexinCountVo selectAdminHomecountHexinShujuzonglan();

    /**
     * 查询资料列表
     *
     * @param fyData 资料
     * @return 资料集合
     */
    public List<FyData> selectFyDataList(FyData fyData);

    @Select("<script>select data_id as dataId,\n" +
            "data_name as dataName,\n" +
            "data_format as dataFormat,\n" +
            "data_url as dataUrl from fy_data " +
            "  <where>\n" +
            "            <if test=\"projectId != null \"> and project_id = #{projectId}</if>\n" +
            "            <if test=\"peopleId != null \"> and people_id = #{peopleId}</if>\n" +
            "            <if test=\"dataType != null  and dataType != ''\"> and data_type = #{dataType}</if>\n" +
            "            <if test=\"dataFormat != null  and dataFormat != ''\"> and data_format = #{dataFormat}</if>\n" +
            "            and is_delete =0\n" +
            "        </where></script>")
    public List<WebFyDataVo> selectwebDataList(@Param("dataType")Long dataType,
                                               @Param("dataFormat") String dataFormat,
                                               @Param("projectId")Long projectId,
                                               @Param("peopleId")Long peopleId);
    @Select("<script>SELECT create_time as createTime, \n" +
            "data_name as dataName,\n" +
            "data_format as dataFormat,\n" +
            "data_url as dataUrl from (\n" +
            "select data_name,data_format,data_url,is_delete,data_type,create_time from fy_data where project_id= #{projectId}\n" +
            "UNION \n" +
            "select data_name,data_format,data_url,is_delete,data_type,create_time from fy_data where people_id in (select people_id from fy_people where project_id= #{projectId})) as fydata " +
            "  <where>\n" +
            "            <if test=\"dataType != null  and dataType != ''\"> and data_type = #{dataType}</if>\n" +
            "            <if test=\"dataFormat != null  and dataFormat != ''\"> and data_format = #{dataFormat}</if>\n" +
            "            and is_delete =0\n" +
            "        </where>" +
            "order by create_time desc</script>")
    public List<WebFyDataVo> selectwebDataListproject(@Param("dataType")Long dataType,
                                                      @Param("dataFormat") String dataFormat,
                                                      @Param("projectId")Long projectId,
                                                      @Param("peopleId")Long peopleId);
    @Select("<script>\n" +
            "SELECT create_time as createTime,\n" +
            "data_name as dataName,\n" +
            "data_format as dataFormat,\n" +
            "data_url as dataUrl from (\n" +
            "select data_name,data_format,data_url,is_delete,data_type,create_time from fy_data where people_id=#{peopleId}\n" +
            "UNION\n" +
            "select data_name,data_format,data_url,is_delete,data_type,create_time from fy_data where project_id =( select project_id from fy_people where people_id=#{peopleId})) as fydata " +
            "  <where>\n" +
            "            <if test=\"dataType != null  and dataType != ''\"> and data_type = #{dataType}</if>\n" +
            "            <if test=\"dataFormat != null  and dataFormat != ''\"> and data_format = #{dataFormat}</if>\n" +
            "            and is_delete =0\n" +
            "        </where></script>")
    public List<WebFyDataVo> selectwebDataListpeople(@Param("dataType")Long dataType,
                                                     @Param("dataFormat") String dataFormat,
                                                     @Param("projectId")Long projectId,
                                                     @Param("peopleId")Long peopleId);
    @Select("<script>\n" +
            "SELECT \n" +
            "data_id as dataId,\n" +
            "data_name as dataName,\n" +
            "data_format as dataFormat,\n" +
            "data_url as dataUrl from fy_data " +
                        "  <where>\n" +
            "            <if test=\"peopleId != null  and peopleId != ''\"> and people_id = #{peopleId}</if>\n" +
            "            <if test=\"dataType != null  and dataType != ''\"> and data_type = #{dataType}</if>\n" +
            "            <if test=\"dataFormat != null  and dataFormat != ''\"> and data_format = #{dataFormat}</if>\n" +
            "            and is_delete =0\n" +
            "        </where></script>")
    public List<WebFyDataVo> selectwebDataListpeopleshi(@Param("dataType")Long dataType,
                                               @Param("dataFormat") String dataFormat,
                                               @Param("projectId")Long projectId,
                                               @Param("peopleId")Long peopleId);

    /**
     * 新增资料
     *
     * @param fyData 资料
     * @return 结果
     */
    public int insertFyData(FyData fyData);

    /**
     * 修改资料
     *
     * @param fyData 资料
     * @return 结果
     */
    public int updateFyData(FyData fyData);

    /**
     * 删除资料
     *
     * @param dataId 资料主键
     * @return 结果
     */
    public int deleteFyDataByDataId(Long dataId);

    /**
     * 批量删除资料
     *
     * @param dataIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFyDataByDataIds(Long[] dataIds);
}
